package sample;

import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

import java.util.ArrayList;

import javafx.event.EventHandler;

/**
 * Created by natalia on 30.12.14.
 */
public class PlayingField extends Pane {
    private int fieldSize = 10;
    private int cellSize = 50;
    ArrayList<ArrayList<Coordinate>> myCoordinates = new ArrayList<ArrayList<Coordinate>>(fieldSize);
    ArrayList<ArrayList<Coordinate>> myEnemyCoordinates = new ArrayList<ArrayList<Coordinate>>(fieldSize);

    PlayingField(int size) {
        this.fieldSize = size;
        drawField();
    }

    void drawField() {
        Rectangle rect;
        rect = new Rectangle(fieldSize, fieldSize);
        getChildren().add(rect);
        rect.setFill(Color.WHITE);

        for(int i = 0; i < fieldSize; i++) {
            for(int j = 0; j < fieldSize; j++) {
                Rectangle innerRectangle = new Rectangle(cellSize, cellSize);
                innerRectangle.setY(i*cellSize);
                innerRectangle.setX(j * cellSize);
                innerRectangle.setFill(Color.WHITE);
                innerRectangle.setStroke(Color.BLACK);
                innerRectangle.setStrokeWidth(0.5);
                getChildren().add(innerRectangle);
            }
        }
    }

    void fillCellWithColor() {
        setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                Rectangle target = (Rectangle)mouseEvent.getTarget();
                target.setFill(Color.RED);
            }
        });
    }

    void drawShips() {
    }

    void setMyShipsCoordinates() {

    }
}
